Skip to content

Add --skip-existing flag to upload command#121

Merged
sigmavirus24 merged 2 commits intopypa:masterfrom
sigmavirus24:bug/115
Sep 13, 2015
Merged

Add --skip-existing flag to upload command#121
sigmavirus24 merged 2 commits intopypa:masterfrom
sigmavirus24:bug/115

Conversation

@sigmavirus24
Copy link
Copy Markdown
Member

This new flag allows users to force twine to skip existing files when
uploading to PyPI. For example:

~/s/gh3.py git:develop ❯❯❯ twine upload --skip-existing dist/*
Uploading distributions to https://pypi.python.org/pypi
Uploading github3.py-1.0.0a2-py2.py3-none-any.whl
  Skipping github3.py-1.0.0a2-py2.py3-none-any.whl because it
appears to already exist
Uploading github3.py-1.0.0a2.tar.gz
  Skipping github3.py-1.0.0a2.tar.gz because it appears to
already exist

Closes #115

@sigmavirus24
Copy link
Copy Markdown
Member Author

@nedbat Would you mind reviewing this as well?

Comment thread twine/commands/upload.py Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is 400 only sent because the file already exists? isn't there some more certain way to know what happened?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite. I don't think trying to match strings in the body of the message will be wise. The status code is consistently 400 in my testing.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But 400 means Bad Request, which could happen for all sorts of reasons, and who knows what might come in the future that would produce 400. I'm not saying "file exists" could produce other status codes, just that sometimes 400 might mean something other than "file exists".

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't disagree. It looks like the reason part of the status line returns something like:

(Pdb) p resp.reason
'A file named "requests_toolbelt-0.4.0-py2.py3-none-any.whl" already exists for  requests-toolbelt-0.4.0. To fix problems with that file you should create a new release.'

Again this seems kind of fragile, but may as well test for it. (To be clear, the behaviour of PyPI in this matter can change very drastically in the coming months given the timeline for Warehouse's release.)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about a compromise: keep this check, but include resp.reason in the message?

This new flag allows users to force twine to skip existing files when
uploading to PyPI. For example:

    ~/s/gh3.py git:develop ❯❯❯ twine upload --skip-existing dist/*
    Uploading distributions to https://pypi.python.org/pypi
    Uploading github3.py-1.0.0a2-py2.py3-none-any.whl
      Skipping github3.py-1.0.0a2-py2.py3-none-any.whl because it
    appears to already exist
    Uploading github3.py-1.0.0a2.tar.gz
      Skipping github3.py-1.0.0a2.tar.gz because it appears to
    already exist

Closes pypa#115
After refactoring the logic out into its own function, it's easier to test
that we will actually be skipping a package upload based on the response and
user preferences.
@sigmavirus24
Copy link
Copy Markdown
Member Author

After refactoring much of the upload module last night, this becomes:

A) Much easier to test
B) Simpler to pull that logic out into its own function so we can test just that.

sigmavirus24 added a commit that referenced this pull request Sep 13, 2015
Add --skip-existing flag to upload command
@sigmavirus24 sigmavirus24 merged commit 47fcbdc into pypa:master Sep 13, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants